package com.hd.common.base;

import java.lang.reflect.InvocationTargetException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts2.ServletActionContext;

import com.hd.common.page.Page;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * <p>Title:Struts2 Action基类</p>
 * <p>Description:</p>
 * <p>copyright:</p>
 * <p>Date: 2008-11-23</p>
 * @version V1.0
 * @amendment history:
 */
public abstract class BaseStruts2Action extends ActionSupport implements ModelDriven<Object> {
	public final static int DEFAULT_PAGE_SIZE = 10;
	public String getCtx() {
		return getRequest().getContextPath();
	}
	public String getUrl(){
		System.out.println(getRequest().getRequestURI().toString());
		System.out.println(getRequest().getRequestURL().toString());
		System.out.println(getRequest().getServletPath().toString());
		return getRequest().getServletPath();
	}
	protected String target;
	public String getTarget() {
		return target;
	}
	public void setTarget(String target) {
		this.target = target;
	}
	
	private int pageNumber;
	public int getPageNumber() {
		return pageNumber;
	}
	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}
	
	protected Page page;
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	
	public abstract Object getModel();
	
	public void copyProperties(Object dest,Object orig) {
		try {
			BeanUtils.copyProperties(dest, orig);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}

	protected HttpServletResponse getResponse(){
		return ServletActionContext.getResponse();
	}
	
	protected HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}
	
}

